import { 
  queryPage,
  queryDetail,
  modifDetail,
  modifPeople,
  modifRoom
} from './service';
import { message } from 'antd';

import { routerRedux } from 'dva/router';

export default {
  namespace: 'message',

  state: {
    list: { data: [] },
    cond: {},
    detail:{},
    dispatchFlag: 1, //1是消控室   2人员  
  },

  effects: {
    *queryPage({ payload = { pageNum: 1, pageSize: 10 } }, { call, put, select }) {
      const response = yield call(queryPage, payload);
      yield put({ type: 'setPage', payload: response })
    },
    //详细查单位
    *queryDetail({payload}, { call, put }) {
      const response = yield call(queryDetail);
      yield put({ type: 'setDetail', payload: response })
    },
    //修改整家
    *modifyDetail({ payload }, { call, put }) {
      const response = yield call(modifDetail, payload)
      message.success(response)
    },
    //dispatchFlag
    *modifDispatchFlag( {payload}, { put}){
      yield put({ type: 'setDispatchFlag', payload})
    },
    //修改人员
    *modifPeople( {payload}, { put, call}){
      let response = yield call(modifPeople, payload)
      yield put({ type: 'queryPage', payload:{pageNum:1, pageSize: 10}})
      message.success(response)

    },
    //修改消控室
    *modifRoom( {payload}, { put, call}){
      let response = yield call(modifRoom, payload)
      yield put({ type: 'queryPage', payload:{pageNum:1, pageSize: 10}})
      message.success(response)

    }
  },

  reducers: {
    setDispatchFlag(state, action){
      return {
        ...state,
        dispatchFlag: action.payload
      }
    },
    setPage(state, action) {
      return {
        ...state,
        list: action.payload
      }
    },
    setDetail(state, action) {
      return {
        ...state,
        detail: action.payload
      }
    },
  }
}
